<?php
/**
 * SuggestsController.php
 *
 * @copyright   2023 thingsworld.com.cn - All Rights Reserved
 * @link        http://thingsworld.com.cn/
 * @author      stiffer.chen <chenl@thingsworld.com.cn>
 * @created     2023-06-16 15:12:49
 * @modified    2023-06-16 15:12:49
 *
 */

namespace App\Http\Controllers;

use App\Repositories\SuggestRepo;
use Illuminate\Http\Request;

class SuggestsController extends BaseModuleController
{
    // 参数信息
    public function params(Request $request)
    {
        try {
            $params = SuggestRepo::params();
            return message('获取成功', true, $params);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function store(Request $request)
    {
        try {
            $suggest = SuggestRepo::store(0);
            return message('提交成功', true, $suggest);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function index(Request $request)
    {
        try {
            $data = SuggestRepo::getList();
            return list_message('获取成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function show(Request $request, $id)
    {
        try {
            $suggest = SuggestRepo::getInfo($id);
            return message('获取成功', true, $suggest);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function modify(Request $request, $id)
    {
        try {
            $suggest = SuggestRepo::store($id);
            return message('更新成功', true, $suggest);
        } catch (\Exception $e) {
            message($e->getMessage(), false);
        }
    }

    public function resolve(Request $request, $id)
    {
        try {
            $suggest = SuggestRepo::resolve($id);
            return message('提交成功', true, $suggest);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function close(Request $request, $id)
    {
        try {
            $suggest = SuggestRepo::close($id);
            return message('关闭成功', true, $suggest);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function destroy(Request $request, $id)
    {
        try {
            SuggestRepo::delete($id);
            return message('删除成功', true);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function export(Request $request)
    {
        try {
            $url = SuggestRepo::export();
            return message('导出成功', true, ['url' => $url]);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }
}